<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="../js/channeltype.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            b.b1{display:block;padding:1px 5px 1px 5px;border:1px solid #E0E0E0;}
        </style>
    </head>
    <body>
        <div id="panel">
            <form id="queryFrm">
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="trhd">
                        <td colspan="3"><h3 class="s1">标签查询</h3></td>
                        <td width="7%">&nbsp;</td>
                        <td colspan="4">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="2%" height="34">&nbsp;</td>
                        <td width="7%" class="r">发布状态：</td>
                        <td width="23%">
                            <select id="pubstate" name="pubstate" style="width:100px;">
                                <option value=""></option>
                                <option value="1">1-是-</option>
                                <option value="0">0-否-</option>
                            </select>
                            <span class="r">
                                <input onClick="TAG.updatePubState();" type="button" id="updateBtn1" value="更新">
                            </span></td>
                        <td class="r">tag关键词：</td>
                        <td width="27%"><input id="tagname" name="tagname" value="" maxlength="20" style="width:120px;" onClick="this.value=''"/></td>
                        <td width="9%" class="r">每页显示：</td>
                        <td width="25%" colspan="2"><select name="listsize" id="listsize">
                                <option value="10">10条</option>
                                <option value="20">20条</option>
                                <option value="50">50条</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">板块类别：</td>
                        <td colspan="3">&nbsp;<script>out_select('channeltype');</script>&nbsp;信息类别：
                            <input type="hidden" name="cid" id="cid" value=""/> 
                            ctp:<input type="text" name="ctp" id="ctp" value="" style="width:100px;" readonly="readonly" onclick="selectCatelogs();"/> 
                            <input type="button" value="清空" onclick="$('#cid').val('');$('#ctp').val('');"/>
                            <span class="r">
                                <input onClick="TAG.updateChannelCatalog();" type="button" id="updateBtn3" value="更新板块/类别">
                            </span></td>
                        <td class="r"><input name="rownum" id="rownum" value="" type="hidden" />
                            <input name="crow" id="crow" value="" type="hidden" />
                            <input name="currpage" id="currpage" value="" type="hidden" />
                            &nbsp;</td>
                        <td colspan="2"><span class="r">
                                <input onClick="TAG.list(1, 0);" type="button" class="button small orange" id="submitBtn" value="Φ 查询">
                                <input onClick="TAG.initAddWin();" type="button" class="button small orange" id="submitBtn" value="Φ 新增标签">
                            </span></td>
                    </tr>
                </table>
            </form>
        </div>


        <div class="databox">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th width="7%">&nbsp;<a href="javascript:ut.swapsel('sel');">反选</a></th>
                    <th width="30%">标签名</th>
                    <th width="27%">审核发布</th>
                    <th width="24%">板块/分类路径</th>
                    <th width="12%">操作</th>
                </tr>
                <tbody class="tbchg" id="datalist"></tbody>
            </table>
        </div>
        <div class="page" id="page"></div>

        <div style="display:block;clear:both;width:98%;height:50px;">&nbsp;</div>





        <!-- 数据处理 -->
        <script id="listTpl" type="text/html">
            {%  for(var k in list){ var e = list[k]; %}
        <tr>
            <td><input name="sel" type="checkbox" value="{%=e.tagid%}"/></td>
            <td><b>{%=e.tagname%}</b></td>
            <td><b>{%=getPubState(e.pubstate)%}</b></td>
            <td>{%=getChannelType(e.channeltype)%} / {%=e.ctp%}</td>
            <td>
                <a href="javascript:;" onclick="TAG.del('{%=e.tagid%}');">删除</a> 
                <a href="javascript:;" onclick="TAG.updateTagname('{%=e.tagid%}','{%=e.tagname%}');">编辑</a>
            </td>
        </tr>
        {%}%}
    </script>

    <script type="text/javascript">
        var $lsout = $('#datalist');
        var $ls = $('#listsize');
        var $rownum = $('#rownum');
        var $crow=$('#crow');
        var $curpage=$('#currpage');
        var TAG={
            list:function(pgno,r){
                var ls = parseInt($ls.val());
                var step =10;
                var cr = (ls * ( pgno - 1 ));
                $rownum.val(r);
                $crow.val(cr);
                $curpage.val(pgno);
                var params = ut.getFormData('#queryFrm');
                params._t=ut.r();
                $.get('../app/tags/list_factor.shtm',params,function(d){
                    var x = d;
                    rn=x.rownum;
                    $rownum.val(rn);
                    if(rn>0){
                        ut.outpage(pgno, rn, 'TAG.list','page', ls, step);
                        $lsout.html(template.render('listTpl',x));
                    }else{
                        $lsout.html('<tr><td colspan="5">暂无数据.</td></tr>');
                        $('#page').html('');
                    }
                }
            );
            },
            del:function(id){
                if(!window.confirm("确定删除么?执行后不可恢复."))return;
                $.get('../app/tags/delete.shtm?t='+ut.r(), "id="+id, function(x){
                    var r = $.trim(x);
                    if(r=='ok'){
                        ut.m('删除成功');
                        TAG.list($curpage.val(),0);
                    }else{
                        ut.m('删除失败. '+r);
                    }
                });
            },
            updateChannelCatalog:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var ct = $('#channeltype').val();
                var cid = $('#cid').val();
                var ctp = $('#ctp').val();
                if(!va.mint(ct) || !va.isint(cid)){ut.m('请选择板块、信息类别.');return;}
                var p = {'ids':ida, 'cid':cid, 'ctp':ctp, 'channeltype':ct};
                $.get('../app/tags/update_channel_catelog.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        TAG.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });   
            },
            updatePubState:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var st = $('#pubstate').val();
                if(va.isnull(st)){ut.m('请选择发布状态.');return;}
                var p = {'ids':ida,'pubstate':st};
                $.get('../app/tags/update_pubstate.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        TAG.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            updateTagname:function(id,name){
                var na = window.prompt('tagID='+id+',tagName='+name+'. 请输入新名称:',name);
                if(va.isnull(na)){return;}
                $.get('../app/tags/update_tagname.shtm?t='+ut.r(), "tagid="+id+"&tagname="+ut.enc(na), function(x){
                    var r = $.trim(x);
                    if(r=='ok'){
                        TAG.list($curpage.val(),0);
                    }else{
                        ut.m('修改名称失败. '+r);
                    } 
                });
            },
            initAddWin:function(){
                var cid = $('#cid').val();
                var ctp = $('#ctp').val();
                var ct = $('#channeltype').val();
                if(va.isnull(cid)){ut.m('请先选择类别.');return;}
                TxBox.winpop(420, 160, '添加新tag', 'tags_add_pop.html?cid='+cid+'&ctp='+ctp+'&channeltype='+ct+'&t='+ut.r()+'&page='+$curpage.val());
            }
        };
            
        function selectCatelogs(){
            var ct = $('#channeltype').val();
            if(!va.mint(ct)){
                TxBox.alert('请先选择板块.');
                return;
            }
            TxBox.winpop(250,350,'类目选择', 'catalogs_select_pop.html?channeltype='+ct);
        };

        function reloadCatData(cid,ctp){
            $('#cid').val(cid);
            $('#ctp').val(ctp);
            $('#ctp_name_path').text(cid+';'+ctp);
            TxBox.closeWinpop();
        };
            
        template.helper('getChannelType',getChannelType);
        template.helper('getPubState',getPubState);
            
        jQuery(function(){
            $('#channeltype').val('0');
            $('#channeltype').change(function(){
                $('#cid').val('');
                $('#ctp').val('');
            });
        });
    </script>
</body>
</html>
